'use strict';
app.service('industryService',['$http','$q','utilService',function($http,$q,utilService){

    this.getIndustryList = function($scope){
        var deferred = $q.defer();
        $http.get($scope.app.domain + '/industry'
        ).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        });
        return deferred.promise;
    }

    this.getIndustryFullName = function($scope){
        var deferred = $q.defer();
        $http.get($scope.app.domain + '/industry/get/industry/list'
        ).then(function(reslut){
            deferred.resolve(reslut.data);
        },function(e){
            deferred.reject("连接服务器出错");
        });
        return deferred.promise;
    }

    this.addIndustry = function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + '/industry',
            data:$scope.industry
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }

    this.delIndustry = function($scope,id){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'industry/'+ id,
            data:{id:id}
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }

    this.getIndustryById = function(id){
        var deferred = $q.defer();
        $http.get($scope.app.domain + 'industry/'+id
        ).then(function(reslut){
                deferred.resolve(reslut.data);
            },function(e){
                deferred.reject("连接服务器出错");
            });
        return deferred.promise;
    }

    this.updateIndustry = function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'industry/update',
            data:$scope.items,
            method:"PUT"
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }


}]);